package com.thesis.client;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.thesis.object.ListUsers;

public class UserAdapter extends BaseAdapter {
	private final Context context;
	private final ListUsers lisUser;

	public UserAdapter(Context context, ListUsers lisUser) {

		this.context = context;
		this.lisUser = lisUser;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View rowView;
		if (convertView == null) {
			rowView = new View(context);
			rowView = inflater.inflate(R.layout.item_user, parent, false);
		} else {
			rowView = (View) convertView;
		}

		TextView textView = (TextView) rowView.findViewById(R.id.us_tv_name);
		ImageView imageView = (ImageView) rowView.findViewById(R.id.us_iv_pic);
		textView.setText(ListUsers.getInstance().getListUser().get(position)
				.getLastName()
				+ " "
				+ ListUsers.getInstance().getListUser().get(position)
						.getFirstName());
		String imagePath;
		if (!ListUsers.getInstance().getListUser().get(position).getImage().equals("")){
			imagePath = Environment.getExternalStorageDirectory().toString() 
					+ "/restautant/user/" +ListUsers.getInstance().getListUser().get(position).getImage();
			imageView.setImageDrawable(Drawable.createFromPath(imagePath));
		} else {
//			imagePath = Environment.getExternalStorageDirectory().toString() 
//					+ "/restautant/user/no-image.jpg";
			imageView.setImageResource(R.drawable.no_image);
		}
		
		
//		String imagePath = Environment.getExternalStorageDirectory().toString() 
//				+ "/restautant/user/" +ListUsers.getInstance().getListUser().get(position).getImage();
		// setting downloaded into image view
		
		//imageView.setImageResource(R.drawable.user);

		return rowView;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return ListUsers.getInstance().getListUser().size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
}
